package com.zero.basic.dao;

import java.util.List;
import java.util.Map;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

@Repository("hqlListBaseDao")
public class HqlListBaseDao<T> extends DefaultBaseDao<T> {

	/**
	 * list: query all the Object using HQL
	 * 
	 * @param hql
	 * @param args
	 * @return
	 */
	public List<T> list(String hql, Object[] args) {
		return this.list(hql, args, null);
	}

	public List<T> list(String hql, Object arg) {
		return this.list(hql, new Object[] { arg });
	}

	public List<T> list(String hql) {
		return this.list(hql, null);
	}

	@SuppressWarnings("unchecked")
	public List<T> list(String hql, Object[] args, Map<String, Object> alias) {
		hql = initSort(hql);
		Query query = getSession().createQuery(hql);
		setAliasParameter(query, alias);
		setParameter(query, args);
		return query.list();
	}

	public List<T> listByAlias(String hql, Map<String, Object> alias) {
		return this.list(hql, null, alias);
	}
}